package com.cw.jeeyt.service.impl.system;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.cw.jeeyt.dao.model.system.SysScaffoldModuleDo;
import com.cw.jeeyt.dao.query.system.SysScaffoldModuleQuery;
import com.cw.jeeyt.service.intf.system.SysScaffoldModuleService;
import com.cw.jeeyt.service.bo.system.SysScaffoldModuleBo;
import com.cw.jeeyt.service.converter.system.SysScaffoldModuleConverter;
import com.cw.jeeyt.dao.intf.system.SysScaffoldModuleDao;
import com.cw.lang.common.utils.SequenceTool;
import com.cw.lang.mybatis.dto.PageInfo;
import com.cw.lang.mybatis.dto.PageParam;

/**
 * 脚手架模块接口业务实现类
 *
 * @author admin
 * @date 2020-05-26 15:00:07
 */
@Service
public class SysScaffoldModuleServiceImpl implements SysScaffoldModuleService {
    @Autowired
    private SysScaffoldModuleDao sysScaffoldModuleDao;

    /**
     * 新增脚手架模块
     *
     * @param request 条件
     * @return Long
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long insert(SysScaffoldModuleBo request) {
        if (request == null) {
            return null;
        }
        Long id = SequenceTool.nextLongId();
        request.setId(id);
        sysScaffoldModuleDao.insertBySelective(SysScaffoldModuleConverter.bo2Do(request));
        return id;
    }

    /**
     * 更新脚手架模块
     *
     * @param request 条件
     * @return boolean
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean modify(SysScaffoldModuleBo request) {
        if (request == null) {
            return false;
        }
        sysScaffoldModuleDao.updateBySelective(SysScaffoldModuleConverter.bo2Do(request));
        return true;
    }

    /**
     * 删除脚手架模块
     *
     * @param request 条件
     * @return boolean
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean delete(SysScaffoldModuleBo request) {
        if (request == null) {
            return false;
        }
        return sysScaffoldModuleDao.deleteByKey(request.getId()) > 0;
    }

    /**
     * 分页查询脚手架模块
     *
     * @param request 条件
     * @return PageInfo<SysScaffoldModuleBo>
     */
    @Override
    public PageInfo<SysScaffoldModuleBo> selectPage(SysScaffoldModuleBo request, PageParam pageParam) {
        PageInfo<SysScaffoldModuleDo> pageInfo = sysScaffoldModuleDao.selectPage(SysScaffoldModuleQuery.builder()
            .id(request.getId())
            .moduleCode(request.getModuleCode())
            .moduleName(request.getModuleName())
            .build(), pageParam);
        List<SysScaffoldModuleBo> sysScaffoldModules = SysScaffoldModuleConverter.doList2BoList(pageInfo.getList());
        return new PageInfo<>(pageInfo, sysScaffoldModules);
    }

    /**
     * 查询脚手架模块详情信息
     *
     * @param request 条件
     * @return SysScaffoldModuleBo
     */
    @Override
    public SysScaffoldModuleBo queryDetail(SysScaffoldModuleBo request) {
        if (request == null) {
            return null;
        }
        return SysScaffoldModuleConverter.do2Bo(sysScaffoldModuleDao.selectByKey(request.getId()));
    }

    /**
     * 根据条件查询脚手架模块
     *
     * @param request 条件
     * @return List<SysScaffoldModuleBo>
     */
    @Override
    public List<SysScaffoldModuleBo> queryList(SysScaffoldModuleBo request) {
        if (request == null) {
            return null;
        }
        return SysScaffoldModuleConverter.doList2BoList(sysScaffoldModuleDao.selectByExample(
            SysScaffoldModuleQuery.builder()
                .id(request.getId())
                .moduleCode(request.getModuleCode())
                .moduleName(request.getModuleName())
                .build()));
    }

    /**
     * 根据key查询脚手架模块
     *
     * @param id
     * @return
     */
    @Override
    public SysScaffoldModuleBo selectByKey(Long id) {

        return SysScaffoldModuleConverter.do2Bo(sysScaffoldModuleDao.selectByKey(id));
    }
}
